package web.common.internal.jdo.mapper;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDate;

/**
 * @author Jin Zheng
 * @since 2021-12-13
 */
public class LocalDateRowMapper implements RowMapper<LocalDate> {
	public LocalDateRowMapper() {
	}

	@Override
	public LocalDate mapRow(ResultSet rs, int row) throws SQLException {
		var meta = rs.getMetaData();
		if (meta.getColumnCount() < RowMapperFactory.ONE) {
			return null;
		}
		var val = rs.getDate(RowMapperFactory.ONE);
		return rs.wasNull() ? null : val.toLocalDate();
	}
}
